package com.happy_hao.msg.util;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.happy_hao.msg.exception.ServiceException;
import com.happy_hao.msg.mapper.TemplateMapper;
import com.happy_hao.msg.po.Template;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class TemplateUtil {

    @Resource
    private TemplateMapper templateMapper;

    public Template getTemplate(Object identifier){
        Template template;
        QueryWrapper<Template> queryWrapper = new QueryWrapper<>();
        if(identifier == null){
            throw new ServiceException("您传入的标识符为空");
        }else if(identifier instanceof String) {
            template = templateMapper.selectOne(queryWrapper.eq("title", identifier));
        }else if (identifier instanceof Long) {
            template = templateMapper.selectOne(queryWrapper.eq("template_id", identifier));
        }else {
            throw new ServiceException("您传入的标识符不合法");
        }
        return template;
    }

}
